<?php

use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use kartik\grid\GridView;
use backend\modules\supplier\models\Storage;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\supplier\models\SlotSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '货位';
$this->params['breadcrumbs'][] = $this->title;

$storageSelect = array_merge ( [''=>'不过滤'] ,  ArrayHelper::map(Storage::getAll(), 'id', 'name') );
?>
<div class="slot-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('新建', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            [
                'attribute' => 'storage_id',
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=>$storageSelect, 
                'content' => function($data, $row) {
                    return $data->storage->name;
                },
            ],
            [
                'attribute' => 'rack_id',
                //'filterType'=>GridView::FILTER_SELECT2,
                //'filter'=>$storageSelect, 
                'content' => function($data, $row) {
                    return $data->rack->name;
                },
            ],
            'name',
            'length',
            'width',
            'height',
            'sort',
            
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

</div>
